home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
objtools
/
makeoct.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
4KB
|
149 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* makeoct -
* Make an octant of a sphere.
*
* Paul Haeberli - 1990
*/
#include "stdio.h"
#include "sgiobj.h"
#include "vect.h"
sgiobj *makeoct();
main(argc,argv)
int argc;
char **argv;
{
int depth;
sgiobj *obj;
if(argc<3) {
fprintf(stderr,"usage: makeoct outfile depth\n");
exit(1);
}
depth = atoi(argv[2]);
obj = makeoct(8,depth);
writesgiobj(argv[1],obj);
}
static float odata[6][3] = {
{1, 0, 0},
{-1, 0, 0},
{0, 1, 0},
{0, -1, 0},
{0, 0, 1},
{0, 0, -1}
};
static long ondex[8][3] = {
{4, 3, 0}, {4, 1, 3},
{4, 2, 1}, {4, 0, 2},
{5, 2, 0}, {1, 2, 5},
{5, 0, 3}, {1, 5, 3}
};
sgiobj *makeoct(sides,depth)
int sides,depth;
{
int s, i, j, k, n, ntris;
float *v0, *v1, *v2;
float w[4][3];
float t[4][3];
float t0[3], t1[3],t2[3];
float *fptr;
sgiobj *obj;
if(sides>8)
sides = 8;
ntris = sides*depth*depth;
obj = (sgiobj *)newtriobj(ntris);
fptr = (float *)obj->data;
for(s=0; s<sides; s++) {
v0 = odata[ondex[s][0]];
v1 = odata[ondex[s][1]];
v2 = odata[ondex[s][2]];
vset(t0,0.0,0.0,0.0);
vset(t1,1.0,0.0,0.0);
vset(t2,0.5,1.0,0.0);
for(i=0; i<depth; i++) {
for (j = 0; (i + j)<depth; j++) { /* do one piece of row */
k = depth-i-j;
for(n=0; n<3; n++) {
w[0][n] = (i+0)*v0[n] + (j+0)*v1[n] + (k+0)*v2[n];
w[1][n] = (i+1)*v0[n] + (j+0)*v1[n] + (k-1)*v2[n];
w[2][n] = (i+0)*v0[n] + (j+1)*v1[n] + (k-1)*v2[n];
w[3][n] = (i+1)*v0[n] + (j+1)*v1[n] + (k-2)*v2[n];
t[0][n] = ((i+0)*t0[n] + (j+0)*t1[n] + (k+0)*t2[n])/depth;
t[1][n] = ((i+1)*t0[n] + (j+0)*t1[n] + (k-1)*t2[n])/depth;
t[2][n] = ((i+0)*t0[n] + (j+1)*t1[n] + (k-1)*t2[n])/depth;
t[3][n] = ((i+1)*t0[n] + (j+1)*t1[n] + (k-2)*t2[n])/depth;
}
for(n=0; n<4; n++)
vnormal(w[n]);
puttri(fptr,w[0],w[1],w[2],t[0],t[1],t[2]);
fptr += 3*PNTLONGS;
if((k-2)>=0) {
puttri(fptr,w[3],w[2],w[1],t[3],t[2],t[1]);
fptr += 3*PNTLONGS;
}
}
}
}
return obj;
}
puttri(fptr,p0,p1,p2,t0,t1,t2)
float *fptr;
vect *p0, *p1, *p2;
vect *t0, *t1, *t2;
{
*fptr++ = p0->x; /* normal */
*fptr++ = p0->y;
*fptr++ = p0->z;
*fptr++ = t0->x; /* texture */
*fptr++ = t0->y;
*fptr++ = t0->z;
*fptr++ = p0->x/2.0;/* position */
*fptr++ = p0->y/2.0;
*fptr++ = p0->z/2.0;
*fptr++ = p1->x; /* normal */
*fptr++ = p1->y;
*fptr++ = p1->z;
*fptr++ = t1->x; /* texture */
*fptr++ = t1->y;
*fptr++ = t1->z;
*fptr++ = p1->x/2.0;/* position */
*fptr++ = p1->y/2.0;
*fptr++ = p1->z/2.0;
*fptr++ = p2->x; /* normal */
*fptr++ = p2->y;
*fptr++ = p2->z;
*fptr++ = t2->x; /* texture */
*fptr++ = t2->y;
*fptr++ = t2->z;
*fptr++ = p2->x/2.0;/* position */
*fptr++ = p2->y/2.0;
*fptr++ = p2->z/2.0;
}